﻿/// <reference path="Jquery.doc.js"/>
$(function() {
    $("#NoteSearch").click(function() {
        if ($.trim($("#searchKey").val()).length > 0) {
            location.href = "../Search.aspx?keys=" + escape($("#searchKey").val());
        }
        else {
            $("#searchKey").focus();
        }
    })
    $(".WantLeave").click(function() {
        $("html,body").animate({ scrollTop: ($(document).height() - $(window).height()) }, 1000, function() { $("#txtLeaveNote").focus(); });
    })
    $(".BottomBack>span").click(function() {
        $("html,body").animate({ scrollTop: -($(document).height() - $(window).height()) }, 1000);
    })
    $("#BtnSend").click(function() {
        SendUserLeave();
    })
    $("#txtLeaveNote").keyup(function() {
        if ($.trim($("#txtLeaveNote").val()).length > 210) {
            $("#txtLeaveNote").val($("#txtLeaveNote").val().substring(0, 209) + "..");
        }
    })
    if ($("#NID").val() == "-1") {
        $("#BtnSend").val("发表留言");
    }

    $(".Faces>img").click(function() {
        $("#txtLeaveNote").val($("#txtLeaveNote").val() + "表情" + $(this).attr("id"));
    })
})

function SendUserLeave() {
    if (($.trim($("#txtLeaveNote").val()).length == 0) || ($("#txtLeaveNote").val() == "[微博对话]：")) {
        alert("^_^ 请先输入内容信息 ...");
        $("#txtLeaveNote").focus();
    }
    else {
        var sex = document.getElementsByName("sex");
        var vSex = "女士";
        for(var i=0;i<sex.length; i++){
            var radio=sex[i];
            if (radio.checked == true) {
                vSex = radio.value;
                break;
            }
        }
        //var vSex = $("#txtSex1").val() + $("#txtSex2").val();
        $.post("../AjaxCommon/Ajax.aspx", { ClassType: "SendLeave", NID: $("#NID").val(), "Note": escape($("#txtLeaveNote").val()), "tname": escape($("#txtName").val()), "sex": escape(vSex), "tel": escape($("#txtTel").val()), "email": escape($("#txtEmail").val()) }, SetBackSend);
    }
}

function SetMes() {
    //异步获取评论数、浏览次数 同时更新浏览次数
    $.post("../AjaxCommon/Ajax.aspx", { ClassType: "NoteLeave", NID: $("#NID").val() }, SetBackValue);
    //获取某个信息的所有评论信息
    $.post("../AjaxCommon/Ajax.aspx", { ClassType: "GetLeave", NID: $("#NID").val() }, SetLeaveMes);
}
function SetBackValue(Data) {
    var jsonValue = eval('(' + Data + ')');
    $(".ReadCount").html(jsonValue.ReadCount);
    $(".LeaveCount").html(jsonValue.LeaveCount);

}

function SetBackSend(Data) {
    if (Data == "True") {
        alert(" 谢谢您的关注^_^.. ");
        $("#txtLeaveNote").val("");
        $(".BottomBack>span").click();
    }
    else {
        alert("信息提交失败了，(>_<) .. ");
    }
}

function SetLeaveMes(Data) {
    if ($.trim(Data).length > 0) {
        var jsonValue = eval('(' + Data + ')');
        if (jsonValue.AllCount > 0) {
            var LeaveMes = "";
            for (i = 1; i < jsonValue.AllCount; i++) {
                LeaveMes += "<div class=\"LeaveTop\"><span class=\"TopLeft\">第[" + i + "]位 来自[<font color=#666666>" + jsonValue.AllNote["T_LeaveIP" + i] + "</font>]的朋友</span><span class=\"TopRight\">" + (jsonValue.AllNote["T_DateTime" + i]) + "</span></div>";
                LeaveMes += "<div class=\"LeaveNotice\">" + RePlaceFace(jsonValue.AllNote["T_LeaveNote" + i]) + "</div>";
                LeaveMes += "<fieldset class=\"ManageBack\" style=\"" + (($.trim((jsonValue.AllNote["T_LeaveReBack" + i])).length > 0) ? "" : "display:none;") + "\">";
                LeaveMes += "<legend> [管理回复]</legend><div  class=\"LeaveReBack\">" + RePlaceFace(jsonValue.AllNote["T_LeaveReBack" + i]) + "</div></fieldset>";
            }
            $(".TopLeaveMes").show(300).html(LeaveMes);
        }
    }
}
function RePlaceFace(Face) {
    Face = Face.toString().replace(/表情一/g, "<img src=\"../Images/Face/1.gif\">");
    Face = Face.toString().replace(/表情2/g, "<img src=\"../Images/Face/2.gif\">");
    Face = Face.toString().replace(/表情3/g, "<img src=\"../Images/Face/3.gif\">");
    Face = Face.toString().replace(/表情4/g, "<img src=\"../Images/Face/4.gif\">");
    Face = Face.toString().replace(/表情5/g, "<img src=\"../Images/Face/5.gif\">");
    Face = Face.toString().replace(/表情6/g, "<img src=\"../Images/Face/6.gif\">");
    Face = Face.toString().replace(/表情7/g, "<img src=\"../Images/Face/7.gif\">");
    Face = Face.toString().replace(/表情8/g, "<img src=\"../Images/Face/8.gif\">");
    Face = Face.toString().replace(/表情9/g, "<img src=\"../Images/Face/9.gif\">");
    Face = Face.toString().replace(/表情10/g, "<img src=\"../Images/Face/10.gif\">");
    Face = Face.toString().replace(/表情11/g, "<img src=\"../Images/Face/11.gif\">");
    Face = Face.toString().replace(/表情12/g, "<img src=\"../Images/Face/12.gif\">");
    Face = Face.toString().replace(/表情13/g, "<img src=\"../Images/Face/13.gif\">");
    Face = Face.toString().replace(/表情14/g, "<img src=\"../Images/Face/14.gif\">");
    Face = Face.toString().replace(/表情15/g, "<img src=\"../Images/Face/15.gif\">");
    return Face;
}
//获取GET参数值
function GetRequest(str, url) {
    if (!url) {
        url = window.location.href;
    }

    var r = null;
    if (url == null || url == "") return r;
    if (str == null || str == "") return r;
    if (url.indexOf('?') < 0) return r;

    var sp1 = url.split('?');
    if (sp1.length < 1) return r;

    if (sp1[1].indexOf(str) < 0) return r;

    var sp2 = sp1[1].split('&');

    if (sp2.length > 1) {
        for (var i = 0; i < sp2.length; i++) {
            if (sp2[i].indexOf('=') < 0) continue;
            var sp3 = sp2[i].split('=');
            if (sp3.length < 1) continue;
            if (sp3[0] == str) {
                r = sp3[1];
                break;
            }
        }
    } else {
        if (sp2[0].indexOf('=') < 0) return r;
        var sp3 = sp2[0].split('=');
        if (sp3.length < 1) return r;
        if (sp3[0] == str) r = sp3[1];
    }
    return r;
}
function SetTMes() {
    if (GetRequest("TMS") != null && GetRequest("TMS") != "") {
        $("html,body").animate({ scrollTop: ($(document).height() - $(window).height()) }, 1000, function() { $("#txtLeaveNote").focus();$("#txtLeaveNote").val("[微博对话]：");});
    }
}
function GoBCBBS() {
    var d = document;
    var w = window;
    var f = 'http://t.bcbbs.net';
    var l = d.location;
    var e = encodeURIComponent;
    var p = '' + e(l.href) + '&t=' + e(d.title);
    if (!w.open(f + '/index.php?mod=share&code=share&url=' + p, '', 'toolbar=0,status=0,width=500,height=400')) { l.href = f + '.new' + p; }
}
